package kr.or.javacafe.member.dao;

import java.util.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.orm.ibatis.SqlMapClientTemplate;

import kr.or.javacafe.member.domain.*;


@Repository
public class MemberDAOImpl implements MemberDAO{
	private static final String NAMESPACE = "member.";
	
	@Autowired
	private SqlMapClientTemplate sqlMapClientTemplate;
	
	public SqlMapClientTemplate getSqlMapClientTemplate() {
		return sqlMapClientTemplate;
	}
	
	
	
	@SuppressWarnings("unchecked")
	@Override
	public List<User> selectUserList(User param) {
		return getSqlMapClientTemplate().queryForList(NAMESPACE + "selectUserList", param);
	}
	
	@Override
	public int selectUserListCount(User param) {
		return (Integer)getSqlMapClientTemplate().queryForObject(NAMESPACE + "selectUserListCount", param);
	}
	
	@Override
	public User selectUser(User param) {
		return (User) getSqlMapClientTemplate().queryForObject(NAMESPACE + "selectUser", param);
	}
	
	@Override
	public int selectOverlapUserCount(String strUser) {
		return (Integer) getSqlMapClientTemplate().queryForObject(NAMESPACE + "selectOverlapUserCount", strUser);
	}
	
	@Override
	public void insertUser(User param) {
		getSqlMapClientTemplate().insert(NAMESPACE + "insertUser", param);
		getSqlMapClientTemplate().insert(NAMESPACE + "insertUserRole", param);
		getSqlMapClientTemplate().insert(NAMESPACE + "insertUserTeam", param);
	}
	
	@Override
	public void updateUser(User param) {
		getSqlMapClientTemplate().update(NAMESPACE + "updateUser", param);
	}
	
	@Override
	public void updateUserRoleGrp(User param) {
		getSqlMapClientTemplate().update(NAMESPACE + "updateUserRoleGrpEditTime", param);
		getSqlMapClientTemplate().update(NAMESPACE + "updateUserRoleGrp", param);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<RoleGrp> selectRoleGrpNmList() {
		return getSqlMapClientTemplate().queryForList(NAMESPACE + "selectRoleGrpNmList");
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<UserHistory> selectUserHistory(UserHistory param) {
		return getSqlMapClientTemplate().queryForList(NAMESPACE + "selectUserHistory", param.getId());
	}
	
	@Override
	public void insertUserHistory(UserHistory param) {
		getSqlMapClientTemplate().update(NAMESPACE + "insertUserHistory", param);
	}
	
	@Override
	public void deleteUserHistory(UserHistory param) {
		getSqlMapClientTemplate().update(NAMESPACE + "deleteUserHistory", param);
	}
	
	@Override
	public void updateUserTeam(UserTeam param) {
		getSqlMapClientTemplate().update(NAMESPACE + "updateUserTeam", param);
	}

	@Override
	public void updateUserTeamIntroduction(UserTeam param) {
		getSqlMapClientTemplate().update(NAMESPACE + "updateUserTeamIntroduction", param);
	}
}





